/**
 * 
 */
package edu.isistan.genetic.operators;

import java.util.Vector;

import edu.isistan.metamodel.Array;
import edu.isistan.metamodel.Collection;
import edu.isistan.metamodel.Composed;
import edu.isistan.metamodel.DataType;

/**
 * @author mtrotti
 *
 */
public class Flatten implements Operator {

	@Override
	public String toString() {
		return "Flatten []";
	}

	/* (non-Javadoc)
	 * @see Operators.Operator#isCompatible(edu.isistan.metamodel.DataType)
	 */
	
	public boolean isCompatible(DataType aDataType) {
		return aDataType.isCompoused() && !aDataType.isCollection();
	}
	
	
	public boolean isEncapsulationCompatible(){
		return false;
	}
	/* (non-Javadoc)
	 * @see Operators.Operator#mutate(edu.isistan.metamodel.DataType)
	 */
	
	public Vector<DataType> mutate(Vector<DataType> aDataTypes){
		Vector<DataType> aResultSet=new Vector<DataType>();
		for(DataType aComposedType : aDataTypes){
			if (this.isCompatible(aComposedType))
				if (aComposedType.isArray()){
					Composed aArrayType= (Composed)((Collection)aComposedType).getDataType();
					for (DataType dataType : aArrayType.getDataTypes()) {
						Array aNewType= new Array(dataType.getName(), dataType, dataType.getDoc());
						aResultSet.add(aNewType);
					}
				}else
					aResultSet.addAll(((Composed)aComposedType).getDataTypes());
		}
		return aResultSet;
	}

}
